﻿using System;
using System.Activities;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wicresoft.AppFlow.Activities
{
    /// <summary>
    /// Represent for a state activity
    /// </summary>
    /// <typeparam name="T">T should be any object that will be set when the bookmark is resumed</typeparam>
    public abstract class StateActivity<T> : NativeActivity<T>
    {
        protected override bool CanInduceIdle
        {
            get
            {
                return true;
            }
        }

        protected NativeActivityContext cont = null;

        protected abstract string BookmarkName { get; }
        protected abstract T ResumeBookmark(NativeActivityContext context, Bookmark bookmark, object value);

        private void StateChanged(NativeActivityContext context, Bookmark bookmark, object value)
        {
            T result = ResumeBookmark(context, bookmark, value);
            this.Result.Set(context, result);
        }

        protected override void Execute(NativeActivityContext context)
        {
            cont = context;
           
            context.CreateBookmark(BookmarkName, StateChanged);
        }
    }
}
